unit untExibePadrao;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, ActnList, cxPropertiesStore, cxContainer, cxEdit,
  cxClasses, cxStyles, cxGridTableView, cxLookAndFeels,
  cxGridCustomPopupMenu, cxGridPopupMenu, ImgList, cxGraphics, DB,
  IBCustomDataSet, dxBarDBNav, dxBar, cxCustomData, cxFilter, cxData,
  cxDataStorage, cxDBData, cxGridLevel, cxControls, cxGridCustomView,
  cxGridCustomTableView, cxGridDBTableView, cxGrid, cxPC,cxStorage,
  cxLookAndFeelPainters, dxSkinsCore, dxSkinBlack, dxSkinBlue,
  dxSkinCaramel, dxSkinCoffee, dxSkinDarkRoom, dxSkinDarkSide, dxSkinFoggy,
  dxSkinGlassOceans, dxSkiniMaginary, dxSkinLilian, dxSkinLiquidSky,
  dxSkinLondonLiquidSky, dxSkinMcSkin, dxSkinMoneyTwins,
  dxSkinOffice2007Black, dxSkinOffice2007Blue, dxSkinOffice2007Green,
  dxSkinOffice2007Pink, dxSkinOffice2007Silver, dxSkinOffice2010Black,
  dxSkinOffice2010Blue, dxSkinOffice2010Silver, dxSkinPumpkin, dxSkinSeven,
  dxSkinSharp, dxSkinSilver, dxSkinSpringTime, dxSkinStardust,
  dxSkinSummer2008, dxSkinsDefaultPainters, dxSkinValentine,
  dxSkinXmas2008Blue, dxSkinscxPCPainter, dxSkinsdxBarPainter;

type
  TfrmExibePadrao = class(TForm)
    cxImageList1: TcxImageList;
    GridPopupMenu: TcxGridPopupMenu;
    cxPropertiesStore: TcxPropertiesStore;
    ActionList1: TActionList;
    ActFirst: TAction;
    ActPrior: TAction;
    ActNext: TAction;
    ActLast: TAction;
    ActInsert: TAction;
    ActDelete: TAction;
    ActEdit: TAction;
    ActSave: TAction;
    ActCancel: TAction;
    ActRefresh: TAction;
    ActFilter: TAction;
    ActFechar: TAction;
    ActESC: TAction;
    ActContrair: TAction;
    ActExpandir: TAction;
    ActExportar: TAction;
    ActConfigurar: TAction;
    ActCadLookup: TAction;
    dtEdit: TIBDataSet;
    dsRegistro: TDataSource;
    dxBarManager: TdxBarManager;
    dxBarManager1Bar1: TdxBar;
    btnInsert: TdxBarButton;
    btnDelete: TdxBarButton;
    btnSalvar: TdxBarButton;
    btnEditar: TdxBarButton;
    btnCancelar: TdxBarButton;
    dxBarDBNavFirst1: TdxBarDBNavButton;
    dxBarDBNavPrior1: TdxBarDBNavButton;
    dxBarDBNavNext1: TdxBarDBNavButton;
    dxBarDBNavLast1: TdxBarDBNavButton;
    dxBarDBNavDelete1: TdxBarDBNavButton;
    dxBarDBNavEdit1: TdxBarDBNavButton;
    dxBarDBNavPost1: TdxBarDBNavButton;
    dxBarDBNavCancel1: TdxBarDBNavButton;
    dxBarDBNavRefresh1: TdxBarDBNavButton;
    dxBarDBNavInsert1: TdxBarDBNavButton;
    btnCustomizar: TdxBarButton;
    btnexportar: TdxBarButton;
    btnContrair: TdxBarButton;
    btnExpandir: TdxBarButton;
    btnImprimir: TdxBarButton;
    dxBarDBNavigator1: TdxBarDBNavigator;
    pgcCadastro: TcxPageControl;
    tbsLista: TcxTabSheet;
    Panel1: TPanel;
    tbsEdita: TcxTabSheet;
    Panel2: TPanel;
    frmTreePadrao: TPanel;
    ActImprimir: TAction;
    ActConfigRel: TAction;
    btnConfigRel: TdxBarButton;
    SaveDialog: TSaveDialog;
    procedure FormCreate(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
    codigo : integer;
  end;

var
  frmExibePadrao: TfrmExibePadrao;

implementation

{$R *.dfm}

procedure TfrmExibePadrao.FormCreate(Sender: TObject);
var
  FMyStream: TMemoryStream;
  DirUser, Diretorio : String;
begin
  cxPropertiesStore.StorageName := TfrmExibePadrao(Sender).Name;
  cxPropertiesStore.StorageType := stStream;
  FmyStream := TMemoryStream.Create;
  cxPropertiesStore.StorageStream := FMyStream;
  DirUser := GetEnvironmentVariable('USERPROFILE');
  // Later I load the Stream from database
  if FileExists(DirUser+'\'+cxPropertiesStore.StorageName) then
  begin
    FMyStream.LoadFromFile(DirUser+'\'+cxPropertiesStore.StorageName);
    FMyStream.Position := 0;
    cxPropertiesStore.RestoreFrom;
  end;

  dtEdit.Close;
  dtEdit.Open;
end;

procedure TfrmExibePadrao.FormClose(Sender: TObject;
  var Action: TCloseAction);
var
  Diretorio :string;
  DirUser : String;
begin
   DirUser := GetEnvironmentVariable('USERPROFILE');
          (cxPropertiesStore.StorageStream as TMemoryStream).Position := 0;
           cxPropertiesStore.StoreTo(true);
          (cxPropertiesStore.StorageStream as TMemoryStream).SaveToFile((DirUser+'\'+cxPropertiesStore.StorageName));

  if dtEdit.fieldbyname('CODIGO').value > 0 then
    Codigo := dtEdit.fieldbyname('CODIGO').value;
end;

end.
